package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.JazBedNumberDO;
import com.jinzhi.jzweb.domain.JazCoursesDO;
import com.jinzhi.jzweb.domain.vo.JazCoursesVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazHouseTypesDO;
import com.jinzhi.jzweb.service.JazHouseTypesService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 房型表
 * </pre>
 * <small> 2024-07-29 08:50:26 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazHouseTypes")
public class JazHouseTypesController extends BaseController {
	@Autowired
	private JazHouseTypesService jazHouseTypesService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:jazHouseTypes:jazHouseTypes")
	String JazHouseTypes(){
	    return "jzweb/jazHouseTypes/jazHouseTypes";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazHouseTypes:jazHouseTypes")
	public Result<Page<JazHouseTypesDO>> list(JazHouseTypesDO jazHouseTypesDTO){
		// 查询列表数据
		Page<JazHouseTypesDO> page = jazHouseTypesService.selectPage(getPage(JazHouseTypesDO.class),
					jazHouseTypesService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazHouseTypesDO obj = (JazHouseTypesDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazHouseTypes:add")
	String add(){
	    return "jzweb/jazHouseTypes/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazHouseTypes:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazHouseTypesDO jazHouseTypes = jazHouseTypesService.selectById(id);
		model.addAttribute("jazHouseTypes", jazHouseTypes);
	    return "jzweb/jazHouseTypes/edit";
	}
	
	@Log(value = "添加房型表",sysModule = 2,operationType = 1)
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazHouseTypes:add")
	public Result<String> save( JazHouseTypesDO jazHouseTypes){
		jazHouseTypesService.insert(jazHouseTypes);
        return Result.ok();
	}
	
	@Log(value = "修改房型表",sysModule = 2,operationType = 3)
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazHouseTypes:edit")
	public Result<String>  update( JazHouseTypesDO jazHouseTypes){
		boolean update = jazHouseTypesService.updateById(jazHouseTypes);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log(value = "删除房型表",sysModule = 2,operationType = 2)
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:questionList:remove")
	public Result<String>  remove( Long id){
        return Result.ok(jazHouseTypesService.remove(id));
	}
	
	@Log(value = "批量删除房型表",sysModule = 2,operationType = 2)
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazHouseTypes:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazHouseTypesService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

	@Log(value = "添加房型表",sysModule = 2,operationType = 1)
	@ResponseBody
	@PostMapping("/saveHouseType")
	public Result<String> saveHouseType(@RequestBody JazHouseTypesDO jazHouseTypesDO){

		return jazHouseTypesService.saveHouseType(jazHouseTypesDO);
	}
	@Log(value = "编辑房型表",sysModule = 2,operationType = 3)
	@ResponseBody
	@PostMapping("/updateHouseType")
	public Result<String> updateHouseType(@RequestBody JazHouseTypesDO jazHouseTypesDO){
		jazHouseTypesService.updateHouseType(jazHouseTypesDO);
		return Result.ok();
	}
	/**
	 *  分页房型列表查询
	 * @return
	 */
	@GetMapping("/selHouseTypeList")
	@ResponseBody
	public Result<Page<JazHouseTypesDO>> selHouseTypeList(@RequestParam(value = "name",required = false) String name,
													@RequestParam(value = "buildNumber",required = false) String buildNumber,
													@RequestParam(value = "status",required = false) Integer status,
													@RequestParam("current")int current,
													@RequestParam("size")int size)  {

		return jazHouseTypesService.selHouseTypeList(name,buildNumber,status,current,size);
	}

	/**
	 *  房型列表(给住宿列表用)
	 * @return
	 */
	@GetMapping("/selHouseList")
	@ResponseBody
	public Result<List<JazHouseTypesDO>> selHouseList()  {
		List<JazHouseTypesDO> jazHouseTypesDOS = jazHouseTypesService.selHouseList();
		return Result.ok(jazHouseTypesDOS);
	}
	/**
	 *  房号列表
	 * @return
	 */
	@GetMapping("/selBedNumberList")
	@ResponseBody
	public Result<List<JazBedNumberDO>> selBedNumberList(@RequestParam(value = "id") Long id)  {
		List<JazBedNumberDO> doList = jazHouseTypesService.selBedNumberList(id);

		return Result.ok(doList);
	}
}
